﻿using System.Net;
using System.Runtime.Serialization;

namespace Toybox.NicoSharp.App
{
	using Extensions;
	using Utilities;

	[DataContract]
	public class PlayerInit
	{

		#region [Static]

		public static PlayerInit Get(CookieCollection cookies = null)
		{
			string url = NicoUrls.AppApi + "player/init/nicovideo.json";
			string json = NicoWebClient.Get(url, cookies.Coerce());
			return Deserializer.JsonDeserializer<PlayerInit>(json);
		}

		#endregion [Static]


		#region Public Members

		/// <summary>
		/// 取得結果
		/// </summary>
		[DataMember]
		public string status;

		[DataMember]
		public string statuscode;

		[DataMember]
		public Result result;

		#endregion Public Members


		#region [SubClass]

		[DataContract]
		public class Result
		{
			[DataMember]
			public MsgServer msgserver;

			[DataMember]
			public Plugin[] plugins;

			[DataMember]
			public Statuses statuses;

			[DataMember]
			public Promotion promotion;
		}

		[DataContract]
		public class MsgServer
		{
			[DataMember]
			public string host;

			[DataMember]
			public int port;
		}

		[DataContract]
		public class Plugin
		{
			[DataMember]
			public string app_id;

			[DataMember]
			public int app_type;

			[DataMember]
			public string title;

			[DataMember]
			public bool is_dev;

			[DataMember]
			public string version;

			[DataMember]
			public string swf_url;

			[DataMember]
			public string icon_url;

			[DataMember]
			public Thread threads;
		}

		[DataContract]
		public class Thread
		{
			[DataMember]
			public ThreadInfo running;

			[DataMember]
			public ThreadInfo active;
		}

		[DataContract]
		public class ThreadInfo
		{
			[DataMember]
			public string id;

			[DataMember]
			public string key;
		}

		[DataContract]
		public class Statuses
		{
			[DataMember]
			public int friend_request_count;

			[DataMember]
			public int recent_invitation_count;

			[DataMember]
			public int recent_message_count;
		}

		[DataContract]
		public class Promotion
		{
			[DataMember]
			public int last_update;
		}

		#endregion [SubClass]

	}
}
